Release 10.1A: OpenEdge Development:
Progress Dynamics Advanced Development


Separating client code from server code

Programming a manager is like programming any other business logic procedure, except that you write code for both sides of the server connection.

When you create a new procedure in the Section Editor, shown in Figure 7–1, you see a DB-Required toggle box in the header section that you can use to indicate whether the code you write goes into the client or server side when the procedure is compiled.

Figure 7–1: Section Editor

By default, the DB-Required toggle box is checked on. When it is on, the entire internal procedure or function you are writing compiles into only the server side .r file for the manager. If you turn it off, it goes into both the client and server files.

When you save your procedure, the AppBuilder writes these additional preprocessor definitions into your source procedure:

/* Db-Required definitions. */ 
&IF DEFINED(DB-REQUIRED) = 0 &THEN 
    &GLOBAL-DEFINE DB-REQUIRED TRUE 
&ENDIF 
&GLOBAL-DEFINE DB-REQUIRED-START   &IF {&DB-REQUIRED} &THEN 
&GLOBAL-DEFINE DB-REQUIRED-END     &ENDIF 

The first of these definitions says that if the DB-REQUIRED preprocessor has not already been defined, then define it to be TRUE. The other two definitions provide for a wrapper around each entry point in the file. Around every function and internal procedure definition you create, the AppBuilder puts the DB-REQUIRED-START and DB-REQUIRED-END preprocessors that compile the entry point in or out, as shown:

{&DB-REQUIRED-START} 
&IF DEFINED(EXCLUDE-testDBRequired) = 0 &THEN 
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE testDBRequired Procedure  
_DB-REQUIRED 
PROCEDURE testDBRequired : 
/*-------------------------------------------------------------------------- 
  Purpose:      
  Parameters:  <none> 
  Notes:        
-------------------------------------------------------------------------*/ 
END PROCEDURE. 
/* _UIB-CODE-BLOCK-END */ 
&ANALYZE-RESUME 
&ENDIF 
{&DB-REQUIRED-END} 

If you look at the template for the client side procedure, you can see why they compile differently:

/* rytstclntp.p - non-db proxy for rytstsrvrp.p */ 
&GLOBAL-DEFINE DB-REQUIRED FALSE 
{"rytstsrvrp.p"} 

This file sets the DB-REQUIRED flag to FALSE before the AppBuilder-generated statement in the main procedure has a chance to set it to TRUE. Therefore, all DB-REQUIRED blocks are left out of the compilation that winds up on the client.


Copyright © 2005 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095